package com.yunxi.controller.vehicle;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.vehicle.pojo.VehicleProductVO;
import com.yunxi.vehicle.service.VehicleProductDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 生产车型 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-11
 */
@RestController
@RequestMapping("/admin/vehicleProduct")
@Api(tags = "base:product", description = "生产车型接口")
public class VehicleProductController {
 private static final Logger logger = LoggerFactory.getLogger(VehicleProductController.class);

 /*@Reference(version = "${demo.service.version}",
         application = "${dubbo.application.id}",
         url = "${dubbo.application.url}",
         check = false,
         timeout = 10000)*/
 @Autowired
 VehicleProductDubboService vehicleProductDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 @ApiImplicitParams(
         {@ApiImplicitParam(paramType = "query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
                 @ApiImplicitParam(paramType = "query", name = "pageSize", value = "分页数量", required = true, dataType = "int")})
 public ApiResult page(VehicleProductVO vehicleProductVO, Integer pageNum, Integer pageSize) throws Exception {
  return ResponseUtil.ok(vehicleProductDubboService.findPageByVO(vehicleProductVO, pageNum, pageSize));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 public ApiResult load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(vehicleProductDubboService.getById(id));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody VehicleProductVO vehicleProductVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  return vehicleProductDubboService.saveOrUpdate(vehicleProductVO);
 }

 @PostMapping("/del")
 @ApiOperation(value = "删除")
 public ApiResult del(@RequestBody List<VehicleProductVO> list) throws Exception {
//    vehicleProductDubboService.removeById(vehicleProductVO.getProductId());
  vehicleProductDubboService.removeByListVo(list);
  return ResponseUtil.ok("success");
 }

 @GetMapping("/productList")
 @ApiOperation(value = "生产车型列表")
 public ApiResult productList() throws Exception {
  return ResponseUtil.ok(vehicleProductDubboService.productList());
 }

}
